package com.zyy.game.tianlong.dao;

import com.zyy.game.tianlong.entity.Player;
import com.zyy.game.tianlong.entity.PlayerExample;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface PlayerMapper {
    long countByExample(PlayerExample example);

    int deleteByExample(PlayerExample example);

    int deleteByPrimaryKey(Integer playerId);

    int insert(Player record);

    int insertSelective(Player record);

    List<Player> selectByExample(PlayerExample example);

    Player selectByPrimaryKey(Integer playerId);

    int updateByExampleSelective(@Param("record") Player record, @Param("example") PlayerExample example);

    int updateByExample(@Param("record") Player record, @Param("example") PlayerExample example);

    int updateByPrimaryKeySelective(Player record);

    int updateByPrimaryKey(Player record);

    /**
     * 查询是否存在这个用户名
     *
     * @param username 用户名
     * @return null:不存在 1:存在
     */
    @Select("SELECT 1 FROM  player WHERE player_name = #{username} limit 1")
    Integer existByUserName(String username);

    /**
     * 查询是否存在这个手机号
     *
     * @param phone 手机号
     * @return null:不存在 1:存在
     */
    @Select("SELECT 1 FROM  player WHERE phone = #{phone} limit 1")
    Integer existByPhone(String phone);

    /**
     * 根据电话号码找
     *
     * @param phone phone
     * @return 玩家
     */
    @Select("SELECT player_id, player_name, coins, bean, phone, photo, sign_count,sign_date,password,pay_password,signature FROM player WHERE phone = #{phone}")
    Player selectByPhone(String phone);


    /**
     * 根据openId找
     *
     * @param openid 微信openId
     * @return 玩家信息
     */
    @Select("SELECT player_id, player_name, coins, bean, phone, photo, sign_count,sign_date,pay_password,signature FROM player WHERE open_id = #{openid}")
    Player selectByOpenId(String openid);

    @Update("UPDATE player SET pay_password = #{payPassWord} WHERE player_id = #{playerId} AND pay_password is NULL")
    int updatePayPassWordById(@Param("playerId") Integer playerId, @Param("payPassWord") String payPassWord);

    @Update("UPDATE player SET password = #{passWord} WHERE phone = #{phone}")
    void updatePassWordByPhone(@Param("phone") String phone, @Param("passWord") String passWord);

    @Select("SELECT sign_count,sign_date,bean FROM player WHERE player_id = #{playerId}")
    Player selectSignById(Integer playerId);
}
